import Taro, { Component } from '@tarojs/taro'
import { AtButton } from 'taro-ui'
import classnames from 'classnames'
import PropsType from 'prop-types'
import { View, Text, Image } from '@tarojs/components'
import '../styles/carorder.scss'
import common from '@/common/'
const countMinPri = common.countMinPri
const carIcon = require('../assete/icon_car.png')

export default class DCarorder extends Component {

  onHandleDetail() {
    this.props.onHandleDetail && this.props.onHandleDetail()
  }

  onHandleFirst(e) {
    e.stopPropagation()
    this.props.onHandleFirst && this.props.onHandleFirst()
  }
  onHandleLast(e) {
    e.stopPropagation()
    this.props.onHandleLast && this.props.onHandleLast()
  }
  render() {
    const {
      className,
      order,
      status,
      list,
      flag,
      tipmoney,
      addre,
      total,
      money,
      firstText,
      lastText,
    } = this.props

    return (
      <View className={classnames('b_carorder', className)} onClick={this.onHandleDetail.bind(this)}>
        <View className='b_carorder__munber'>
          <View className='b_carorder__munber_left'>
            <Text className='b_carorder__munber_text'>编</Text>
            <Text className='b_carorder__munber_item'>{order}</Text>
          </View>
          <View className='b_carorder__munber_status'>{status}</View>
        </View>
        <View className='b_carorder__title'>
          <Image src={carIcon} className='b_carorder__title_icon'></Image>
          <View className='b_carorder__title_content'>
            {
              list && list.map((item, i) => {
                return <Text className='b_carorder__itemtitle' key={i}>{item}</Text>
              })
            }
          </View>
        </View>
        <View className='b_carorder__flag'>
          <View className='b_carorder__flag_list'>
            {
              flag && flag.map((item, j) => {
                return <Text key={j} className='b_carorder__itemflag'>{item}</Text>
              })
            }
          </View>
          <View className='b_carorder__flag_tip'>指导价：
					{window.toFixed(tipmoney)}万/
					<Text>{countMinPri(money, tipmoney)}万
					</Text>
					{/* // {window.toFixed(tipmoney)}万元 */}
          </View>
        </View>
        <View className='b_carorder__addre'>{addre}</View>
        <View className='b_carorder__footer'>
          <View className='b_carorder__footer_left'>
            <Text className='b_carorder__footer_left__total'>共{total}辆</Text>
            <Text className='b_carorder__footer_left__money'>{window.toFixed(money)}万元</Text>
          </View>
          {
            firstText && <AtButton onClick={this.onHandleFirst.bind(this)}>{firstText}</AtButton>
          }
          {
            lastText && <AtButton onClick={this.onHandleLast.bind(this)}>{lastText}</AtButton>
          }
        </View>
      </View>
    )
  }
}

DCarorder.defaultProps = {
  className: '',
  order: '',
  status: '待审核',
  list: ['保时捷718', '2018款', 'Cayman', '2.0T'],
  flag: ['中规', '国六', '蓝/黑'],
  tipmoney: '60.00',
  addre: '广东一二三有限公司',
  total: '1',
  money: '60.99',
  firstText: '',
  onHandleDetail: () => { },
  onHandleFirst: () => { },
  onHandleLast: () => { }
}

DCarorder.PropsType = {
  className: PropsType.oneOfType[PropsType.string, PropsType.object],
  order: PropsType.string,
  status: PropsType.string,
  list: PropsType.array,
  flag: PropsType.array,
  tipmoney: PropsType.string,
  addre: PropsType.string,
  total: PropsType.oneOfType[PropsType.number, PropsType.string],
  money: PropsType.string,
  firstText: PropsType.string,
  onHandleDetail: PropsType.func,
  onHandleFirst: PropsType.func,
  onHandleLast: PropsType.func
}
